package com.xia.wifi;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javax.swing.Timer;
import javax.swing.JComboBox;

public class Swatch extends JFrame {
	static boolean continuePing = true;
	private JFrame frame;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		// BufferedImage dest =null;
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Swatch window = new Swatch();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	
	/**
	 * Create the application.
	 */
	public Swatch() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frame = new JFrame("检查wifi");
		frame.getContentPane().setBackground(Color.WHITE);
		frame.setBounds(100, 100, 491, 352);
		final Timer timer = new Timer(5000, new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				System.out.println("开始");
				WifiUtil.resetWireless();
			}
		});
		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		Dimension frameSize = frame.getSize();
		if (frameSize.height > screenSize.height)
			frameSize.height = screenSize.height;
		if (frameSize.width > screenSize.width)
			frameSize.width = screenSize.width;
		frame.setLocation((screenSize.width - frameSize.width) / 2,
				(screenSize.height - frameSize.height) / 2);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(null);
		JButton btnNewButton = new JButton("关闭有线");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				// TODO
				WifiUtil.shutDownWire();
			}
		});
		btnNewButton.setBounds(115, 32, 108, 43);
		frame.getContentPane().add(btnNewButton);

		JButton btnNewButton_1 = new JButton("开启有线");
		btnNewButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				// TODO
				WifiUtil.enableWire();
			}
		});
		btnNewButton_1.setBounds(115, 106, 108, 43);
		frame.getContentPane().add(btnNewButton_1);

		JButton btnNewButton_2 = new JButton("退出");
		btnNewButton_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				timer.stop();
				WifiUtil.quitWifi();
			     frame.dispose();
			}
		});
		btnNewButton_2.setBounds(295, 246, 114, 43);
		frame.getContentPane().add(btnNewButton_2);

		JButton btnNewButton_3 = new JButton("重启无线");
		btnNewButton_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Runnable run = new Runnable() {
					public void run() {
						//pingDNS();
						timer.start();
					}
				};
				SwingUtilities.invokeLater(run);
			}
		});
		btnNewButton_3.setBounds(115, 177, 108, 43);
		frame.getContentPane().add(btnNewButton_3);
		
		JButton btnNewButton_4 = new JButton("XP");
		btnNewButton_4.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String getfunctionreturn=WifiUtil.commonFunction("vmware");
			}
		});
		btnNewButton_4.setBounds(115, 246, 114, 43);
		frame.getContentPane().add(btnNewButton_4);
		String[] arr = { "打开64", "打开62", "2", "3" };
		final JComboBox comboBox = new JComboBox(arr);
		comboBox.setBounds(295, 35, 114, 37);
		frame.getContentPane().add(comboBox);
		
		JButton btnNewButton_5 = new JButton("确定");
		btnNewButton_5.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String functionname = (String) comboBox.getSelectedItem();
				String getfunctionreturn=WifiUtil.commonFunction(functionname);
				
				System.out.println(getfunctionreturn);
			}
		});
		btnNewButton_5.setBounds(295, 106, 114, 43);
		frame.getContentPane().add(btnNewButton_5);
		
		JButton btnNewButton_6 = new JButton("虚拟机");
		btnNewButton_6.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				WifiUtil.enableVmware();
			}
		});
		btnNewButton_6.setBounds(295, 177, 114, 43);
		frame.getContentPane().add(btnNewButton_6);
	}
}
